import 'dart:convert';

import 'package:encrypt/encrypt.dart';

class AesUtil{
  static final  String _key = "g459e0c557ae4650b19169e4dbvgnhly";
  static final String _iv = "1472583690123456";

  /*
  * Base64加密
  */
  static Future encodeBase64() async {

    var today = DateTime.now();
    var date = today.millisecondsSinceEpoch;

    final key = Key.fromUtf8(_key);
    final iv =IV.fromUtf8(_iv);
    final encrypter = Encrypter(AES(key,mode: AESMode.cbc,));
    final encrypted = encrypter.encryptBytes(utf8.encode('$date'), iv: iv);

    return encrypted.base64;
  }

  /*
  * Base64解密
  */
  static Future<String> decodeBase64(String encryptedStr) async{
    final key = Key.fromUtf8(_key);
    final iv = IV.fromUtf8(_iv);
    final encrypter = Encrypter(AES(key,mode: AESMode.cbc));
    final decrypted = encrypter.decrypt64(encryptedStr, iv: iv);

    return decrypted;
  }

  static Future getLSH(String sfbm) async{
    var today = DateTime.now();
    var date = today.millisecondsSinceEpoch;
    var result = date.toString()+"H"+sfbm;
    return '$result';
  }

  static Future idencode(int id) async{

    final key = Key.fromUtf8(_key);
    final iv = IV.fromUtf8(_iv);
    final encrypter = Encrypter(AES(key,mode: AESMode.cbc));
    final decrypted = encrypter.encryptBytes(utf8.encode('$id'), iv: iv);

    return decrypted.base64;
  }

}